import { Component, type ReactNode } from 'react'
import Events from '../eventbus/Events'

export default class LeftView extends Component {
  constructor (props: Readonly<unknown>) {
    super(props)
    Events.on<number>('changeNum', (n) => this.setState({ num: this.state.num + n }))
  }
  // #region 变量声明
  state: Readonly<{num: number}> = {
    num: 0
  }
  // #endregion

  // #region 事件处理函数

  // #endregion

  // #region 函数

  // #endregion

  // 渲染
  public render(): ReactNode {
    return (
      <div className='left'>
        <div className="title">左边组件</div>
        <p>变量num：{ this.state.num }</p>
        <button onClick={ () => this.setState({ num: this.state.num + 1 }) }>num++</button>
        <button onClick={ () => Events.emit('changeSum', 2) }>右边组件的sum+2</button>
      </div>
    )
  }
}

